package src;


import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.ViewPart;

public class PartListenerView extends ViewPart {

	private Table content;
	
	public PartListenerView() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void createPartControl(Composite parent) {
		//Create the table we'll be using to display what we learn
		content = new Table(parent, 0);
		content.setHeaderVisible(false);
	
		//Register for notification of newly opened windows
		getSite().getPage().addPartListener(new IPartListener() {

			@Override
			public void partActivated(IWorkbenchPart part) {
				createItem(content, "Part activated: " + part.getTitle());
			}

			@Override
			public void partBroughtToTop(IWorkbenchPart part) {
				createItem(content, "Part brought to top: " + part.getTitle());
			}

			@Override
			public void partClosed(IWorkbenchPart part) {
				createItem(content, "Part closed: " + part.getTitle());
			}

			@Override
			public void partDeactivated(IWorkbenchPart part) {
				createItem(content, "Part deactivated: " + part.getTitle());
			}

			@Override
			public void partOpened(IWorkbenchPart part) {
				createItem(content, "Part opened: " + part.getTitle());
			}
		
		});
	}

	@Override
	public void setFocus() {
		content.setFocus();
	}

	
	private TableItem createItem(Table parent, String text) {
		TableItem item = new TableItem(parent, SWT.NULL);
		item.setText(text);
		return item;
	}
}
